package com.ihighest.app.infox.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.RadioButton;

import com.ihighest.app.common.api.Api;
import com.ihighest.app.common.api.ApiCallback;
import com.ihighest.app.common.api.ApiParam;
import com.ihighest.app.common.api.ApiResult;
import com.ihighest.app.common.kit.SharedPreferencesKit;
import com.ihighest.app.common.kit.ToastKit;
import com.ihighest.app.infox.Const;
import com.ihighest.app.infox.R;

public class TextSizeActivity extends BaseActivity implements OnClickListener {

	private RadioButton max_big;
	private RadioButton max;
	private RadioButton mid;
	private RadioButton min;
	String fontSize = "";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.infox_activity_textsize);

		max = (RadioButton) findViewById(R.id.change_max_size);
		mid = (RadioButton) findViewById(R.id.change_mid_size);
		min = (RadioButton) findViewById(R.id.change_min_size);
		max_big = (RadioButton) findViewById(R.id.change_max_big_size);
		max_big.setOnClickListener(this);
		max.setOnClickListener(this);
		mid.setOnClickListener(this);
		min.setOnClickListener(this);
		fontSize = SharedPreferencesKit.getString(this, Const.SP_TEXTSIZE);
		if (!TextUtils.isEmpty(fontSize)) {
			if ("max".equalsIgnoreCase(fontSize)) {
				max.setChecked(true);
			} else if ("min".equalsIgnoreCase(fontSize)) {
				min.setChecked(true);
			} else if ("max_big".equalsIgnoreCase(fontSize)) {
				max_big.setChecked(true);
			} else if ("mid".equalsIgnoreCase(fontSize)) {
				mid.setChecked(true);
			}
		}
		// if (Constants.target == Constants.max) {
		// max.setChecked(true);
		// } else if (Constants.target == Constants.mid) {
		// mid.setChecked(true);
		// } else {
		// min.setChecked(true);
		// }

		// Constants.changeSize(this, this, true);
		// 设置完singleTask以后,查找栈里面有没有这个activity
	}

	@Override
	public void onClick(View view) {
		// switch (view.getId()) {
		// case R.id.change_max_size:
		// Constants.target = Constants.max;
		// // Constants.changeSize(this, this, false);
		// finish();
		// break;
		// case R.id.change_mid_size:
		// Constants.target = Constants.mid;
		// // Constants.changeSize(this, this, false);
		// finish();
		// break;
		// case R.id.change_min_size:
		// Constants.target = Constants.min;
		// // Constants.changeSize(this, this, false);
		// finish();
		// break;
		// case R.id.change_min_size:
		// Constants.target = Constants.min;
		// // Constants.changeSize(this, this, false);
		// finish();
		// break;
		//
		// }

		switch (view.getId()) {
		case R.id.change_max_big_size:
			fontSize = "max_big";
			break;
		case R.id.change_min_size:
			fontSize = "min";
			break;
		case R.id.change_mid_size:
			fontSize = "mid";
			break;
		case R.id.change_max_size:
			fontSize = "max";
			break;
		}
		if (!TextUtils.isEmpty(SharedPreferencesKit.getString(this, Const.SP_KEY_USER_ID))) {
			// 如果用户已经登录，将设置信息提交
			Api.post("me/setting", ApiParam.create().addParam("key", Const.SP_TEXTSIZE).addParam("value", fontSize), new ApiCallback(this,
					true) {

				@Override
				public void handleSuccess(ApiResult result) {
					SharedPreferencesKit.putString(TextSizeActivity.this, Const.SP_TEXTSIZE, fontSize);
					finish();
				}

				@Override
				public void handleFailure(Exception e, String msg) {

				}
			}, this);
		} else {
			SharedPreferencesKit.putString(TextSizeActivity.this, Const.SP_TEXTSIZE, fontSize);
			ToastKit.showShort(this, "您当前尚未登录，设置信息无法同步");
			finish();
		}
	}

	@Override
	protected void onResume() {
		// Constants.changeSize(this, this, false);
		super.onResume();
	}

}
